#!/bin/bash -e

cnt=1
repo start r16-v2.1.y --all
# ${cnt}. Pull all repos
echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
echo "# ${cnt}. Pull all repos"
list=(build config dl docs lichee/brandy  package prebuilt scripts target toolchain tools)
basepath=`pwd`
for repo in ${list[@]}
do 
echo $repo
cd $repo
pwd
git checkout r16-v2.1.y
cd ${basepath}
done
#repo forall -c git checkout *
repo forall -c git pull
repo forall -c git status
repo forall -c git branch -a
let cnt=cnt+1

# ${cnt}. Create tag
echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
echo "# ${cnt}. Create tag"
cd scripts
./createtag.sh
cd ..
let cnt=cnt+1

# ${cnt}. Build
echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
echo "# ${cnt}. Build"
export FORCE_UNSAFE_CONFIGURE=1
source build/envsetup.sh
lunch astar_nbc-tina
make -j1
pack -d

let cnt=cnt+1

# ${cnt}. Release
echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
echo "# ${cnt}. Release"
pwd

release_version=(`cat tagversion.txt`)
#main_version=${release_version[0]}
#minor_version=${release_version[1]}
mkdir -p ../cubefs_release/${release_version}
cp ./out/astar-nbr/*${release_version}.img ../cubefs_release/${release_version}
